import '../util/polyfill';
import * as React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-redux';
import getRoutes from '../routes/index';
import configureStore from '../util/configure-store';
import {Router, browserHistory} from 'react-router';


// /*<debug>*/
// // https://github.com/garbles/why-did-you-update
// // 及时发现多余重复渲染.
// import {whyDidYouUpdate} from 'why-did-you-update';
// whyDidYouUpdate(React);
// /*</debug>*/

export function bootstrap(mountTo, initialState) {
  const store = configureStore(initialState);
  const routes = getRoutes(store);

  browserHistory.listen(location => store.dispatch({
    type: 'ROUTER_CHANGE',
    payload: location
  }));

  render(
    <Provider store={store}>
      <Router history={browserHistory}>
        {routes}
      </Router>
    </Provider>
    , mountTo);
}
